package com.springboot.frame.starter.intf;//package com.springboot.frame.starter.web.intf;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.lang.reflect.Field;
//import java.lang.reflect.InvocationHandler;
//import java.lang.reflect.Proxy;
//import java.util.Map;
//
///**
// * @author liheng
// * @ClassName ggaga
// * @Description
// * @date 2020-12-23 12:43
// */
//@Slf4j
//public class IntfEncryInterceptor implements HandlerInterceptor {
//    private  String basePackage;
//
//    public IntfEncryInterceptor(String basePackage) {
//        this.basePackage =  basePackage;
//    }
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        System.out.println(">>>>>>>>>>>>>>");
//        // 替换包属性
//        ControllerAdvice decodeRequestBodyAdvice = DecodeRequestBodyAdvice.class.getAnnotation(ControllerAdvice.class);
//        ControllerAdvice encodeResponseBodyAdvice = EncodeResponseBodyAdvice.class.getAnnotation(ControllerAdvice.class);
//        // 获取InvocationHandler
//        InvocationHandler h1 = Proxy.getInvocationHandler(decodeRequestBodyAdvice);
//        InvocationHandler h2 = Proxy.getInvocationHandler(encodeResponseBodyAdvice);
//        // 获取 AnnotationInvocationHandler 的 memberValues 字段
//        try {
//            Field hField1 = h1.getClass().getDeclaredField("memberValues");
//            hField1.setAccessible(true);
//            Map memberValues1 = (Map) hField1.get(h1);
//            // 修改 name,configuration 属性值
//            memberValues1.put("basePackages", basePackage.split(","));
//            memberValues1.put("value", basePackage.split(","));
//
//            Field hField2 = h2.getClass().getDeclaredField("memberValues");
//            hField2.setAccessible(true);
//            Map memberValues2 = (Map) hField2.get(h2);
//            // 修改 name,configuration 属性值
//            memberValues2.put("basePackages", basePackage.split(","));
//            memberValues2.put("value", basePackage.split(","));
//            System.out.println("hhhhhhhhhhhhhhhhhhhhhhhh");
//        } catch (NoSuchFieldException | IllegalAccessException e) {
//            log.error("注解值替换失败，无法进行接口加密");
//        }
//        return true;
//    }
//}
